package com.wolfalpha.utron.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.wolfalpha.utron.R;

/**
 * Created by luodon on 15/8/17.
 */
public class RegisterPwd extends Fragment {

    //对父Activity的接口
    private RegisterPwdListener mlistener;

    public interface RegisterPwdListener {
        public void onFinished(String pwd);

        public void onEnterMain();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.activity_register_pwd, container, false);

        final EditText etPwd = (EditText) view.findViewById(R.id.et_password);
        final EditText etConfirm = (EditText) view.findViewById(R.id.et_confirm);
        Button brnEnter = (Button) view.findViewById(R.id.btn_now_enter);

        etConfirm.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (etPwd.getText().toString().trim().equals(etConfirm.getText().toString().trim())) {
                    mlistener.onFinished(etPwd.getText().toString().trim());
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        brnEnter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mlistener.onEnterMain();
            }
        });

        return view;
    }

    public void setPwdListener(RegisterPwdListener listener) {
        this.mlistener = listener;
    }
}
